﻿#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

typedef struct TContext_s
{
	int x;
}TContext;

TContext context;

int new_value(int a)
{
	return (a + 9) % 10;
}

void swap(int* a, int* b)
{
	int c = *a;
	*a = *b;
	*b = c;
}

int encrypted(int x)
{
	int c[4] = { 0 };
	for (int i = 0; i < 4; ++i)
		c[i] = 0;
	int k = 0;
	while (x && k < 4)
	{
		c[k++] = new_value(x % 10);
		x /= 10;
	}
	for (int i = k; i < 4; ++i)
		c[i] = new_value(0);
	swap(c, c + 2);
	swap(c + 1, c + 3);
	int ret = 0;
	for (int i = 3; i >= 0; --i)
	{
		ret = ret * 10 + c[i];
	}
	return ret;
}

void read_data(TContext* ctx)
{
	scanf("%d", &ctx->x);
}

void do_task(TContext* ctx)
{
	printf("The encrypted number is %04d\n", encrypted(ctx->x));
}

void solve(TContext* ctx)
{
	read_data(ctx);
	do_task(ctx);
}

int main()
{
	freopen("D:/Develop/GitRepos/MOOC/浙江大学/数据结构/201906/DataStructure/M2019秋C入门和进阶练习集/7-117.txt", "r", stdin);
	solve(&context);
	return 0;
}
